package com.ruoyi.business.controller;

import java.util.List;

import com.ruoyi.common.annotation.RepeatSubmit;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.JtCountryCode;
import com.ruoyi.business.service.IJtCountryCodeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 国家码Controller
 * 
 * @author Alan Zhang
 * @date 2025-03-31
 */
@Controller
@RequestMapping("/business/country")
public class JtCountryCodeController extends BaseController
{
    private String prefix = "business/country";

    @Autowired
    private IJtCountryCodeService jtCountryCodeService;

    @RequiresPermissions("business:country:view")
    @GetMapping()
    public String country()
    {
        return prefix + "/country";
    }

    /**
     * 查询国家码列表
     */
    @RequiresPermissions("business:country:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JtCountryCode jtCountryCode)
    {
        startPage();
        List<JtCountryCode> list = jtCountryCodeService.selectJtCountryCodeList(jtCountryCode);
        return getDataTable(list);
    }

    /**
     * 导出国家码列表
     */
    @RequiresPermissions("business:country:export")
    @Log(title = "国家码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JtCountryCode jtCountryCode)
    {
        List<JtCountryCode> list = jtCountryCodeService.selectJtCountryCodeList(jtCountryCode);
        ExcelUtil<JtCountryCode> util = new ExcelUtil<JtCountryCode>(JtCountryCode.class);
        return util.exportExcel(list, "国家码数据");
    }

    /**
     * 新增国家码
     */
    @RequiresPermissions("business:country:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存国家码
     */
    @RequiresPermissions("business:country:add")
    @Log(title = "国家码", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult addSave(JtCountryCode jtCountryCode)
    {
        return toAjax(jtCountryCodeService.insertJtCountryCode(jtCountryCode));
    }

    /**
     * 修改国家码
     */
    @RequiresPermissions("business:country:edit")
    @GetMapping("/edit/{countryId}")
    public String edit(@PathVariable("countryId") Long countryId, ModelMap mmap)
    {
        JtCountryCode jtCountryCode = jtCountryCodeService.selectJtCountryCodeByCountryId(countryId);
        mmap.put("jtCountryCode", jtCountryCode);
        return prefix + "/edit";
    }

    /**
     * 修改保存国家码
     */
    @RequiresPermissions("business:country:edit")
    @Log(title = "国家码", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult editSave(JtCountryCode jtCountryCode)
    {
        return toAjax(jtCountryCodeService.updateJtCountryCode(jtCountryCode));
    }

    /**
     * 删除国家码
     */
    @RequiresPermissions("business:country:remove")
    @Log(title = "国家码", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jtCountryCodeService.deleteJtCountryCodeByCountryIds(ids));
    }


    /**
     * 查询国家码列表
     */
    @GetMapping("/select/list")
    @ResponseBody
    public AjaxResult selectList()
    {
        JtCountryCode param = new JtCountryCode();
        param.setStatus(0);
        List<JtCountryCode> list = jtCountryCodeService.selectJtCountryCodeList(param);

        AjaxResult ajax = new AjaxResult();
        ajax.put("code", 200);
        ajax.put("value", list);
        return ajax;
    }
}
